package com.itbaizhan.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itbaizhan.domain.PayInfo;
import com.itbaizhan.service.PayInfoService;
import com.itbaizhan.mapper.PayInfoMapper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;

/**
* @author 13487
* @description 针对表【pay_info】的数据库操作Service实现
* @createDate 2024-04-23 16:28:22
*/
@Service
public class PayInfoServiceImpl implements PayInfoService{

    @Autowired
    private PayInfoMapper payInfoMapper;
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void save(String account_no, BigDecimal amount) {
        PayInfo payInfo = new PayInfo();
        payInfo.setTxNo(UUID.randomUUID().toString().replace("-"," "));
        payInfo.setAccountNo(account_no);
        payInfo.setPayAmount(amount);
        payInfo.setPayResult("success");
        payInfo.setPayTime(new Date());

        payInfoMapper.insert(payInfo);

        rocketMQTemplate.convertAndSend("notifymsg_topic", JSON.toJSONString(payInfo));
    }

    @Override
    public PayInfo getPayInfoByTxNo(String txNo) {
        return payInfoMapper.selectById(txNo);
    }
}




